﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class DC_Sanction2 : System.Web.UI.UserControl
    {

        Command_DisciplineBLL obj = new Command_DisciplineBLL(); 
     
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
       
        
        {

          
            

        }


        private void BindComboPenalty()
        {
            Command_DisciplineBLL obj = new Command_DisciplineBLL();

            DataTable dt;

            dt = obj.SelectComboPenalty();


            ComboCmmPenalty.DataValueField = "pen_seq";
            ComboCmmPenalty.DataTextField = "pen_name";
            ComboCmmPenalty.DataSource = dt;
            ComboCmmPenalty.DataBind();


        }


        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }


        private void showLBLPanelty(int id)
        {



        }

  
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

          


            if (!IsUserControlPostBack)
            {

                lblPenaltyCombo.Text = Session["m_pen_name"].ToString();  
                BindComboPenalty();
                BindComboCommType();

                this.ViewState.Add("IsUserControlPostBack", true);

            }



            if (DataItem != null)
            {
                //   cbGender.ListGenderComboBox();

     
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {


                    BindComboPenalty();
                    BindComboCommType();

  
                
            

                    lbl_Cmd_dtls_seq.Text = Session["cmd_dtls_seq"].ToString() ;

                    txtCommRefNo.Text = DataBinder.Eval(DataItem, "cmm_ref_no").ToString();
                    txtKopoLaw.Text = DataBinder.Eval(DataItem,"kopo_ref_no").ToString() ;
                    ComboCommType.SelectedValue = DataBinder.Eval(DataItem, "cmm_type").ToString();
                    DateComm.SetValue(DataBinder.Eval(DataItem, "cmm_date").ToString());
                    DateStart.SetValue(DataBinder.Eval(DataItem, "start_date").ToString());
                    ComboCmmPenalty.SelectedValue = DataBinder.Eval(DataItem, "cmm_penalty_seq").ToString();

                    txtCmmMonth.Text = DataBinder.Eval(DataItem, "cmm_month").ToString();
                    txtCmmPercent.Text   = DataBinder.Eval(DataItem, "cmm_deduct_percent").ToString();

                    txtDeductMonth.Text   = DataBinder.Eval(DataItem, "deduct_month").ToString();
                    txtDeductPercent.Text = DataBinder.Eval(DataItem, "deduct_percent").ToString();

                  //  lblClassName.Text = DataBinder.Eval(DataItem, "cr_seq").ToString();

               
             
                }

            
            }


       
      
        }

    

         


        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
   


        protected void btnUpdate_Click(object sender, EventArgs e)
        {

       
            int cmd_dtls_seq;
            cmd_dtls_seq = int.Parse(lbl_Cmd_dtls_seq.Text);


          string cmm_type,cmm_ref_no,cmm_date,kopo_ref_no,start_date;
          int cmm_penalty_seq;

          int deduct_month, cmm_deduct_month;

          decimal deduct_percent,cmm_deduct_percent;

          cmm_type = ComboCommType.SelectedValue;
          cmm_ref_no = txtCommRefNo.Text;
          cmm_date = DateComm.GetStringValue();
          kopo_ref_no = txtKopoLaw.Text;
          start_date = DateStart.GetStringValue();
          cmm_penalty_seq = int.Parse(ComboCmmPenalty.SelectedValue);


          deduct_percent = Convert.ToDecimal  (txtDeductPercent.Text);
          deduct_month = int.Parse(txtDeductMonth.Text);

          cmm_deduct_month = int.Parse(txtCmmMonth.Text);
          cmm_deduct_percent = Convert.ToDecimal(txtCmmPercent.Text);   


        obj.UpdateSanction2(cmd_dtls_seq,cmm_type,cmm_ref_no,cmm_date,
            cmm_penalty_seq,kopo_ref_no,start_date,"1",deduct_percent,deduct_month,cmm_deduct_percent,cmm_deduct_month);      



        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        public void BindComboCommType()
        {
            DataTable dt = new DataTable();
       //     DataColumn dc = dt.Columns.Add("Name");
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("value", typeof(string));

            string name;

            for (int i = 1; i <= 2; i++)
            {
                if(i ==1)
                {
                    name = "กรม";
                }
                else 
                {
                    name = "กระทรวง";
                }

                dt.Rows.Add(name, i); 
           
            }

            ComboCommType.DataTextField = "name";

            ComboCommType.DataValueField = "value";
            ComboCommType.DataSource = dt;
            ComboCommType.DataBind();
        }


        private IEmployeeBLL empBLL = new EmployeeBLL();

        protected void ComboCommType_TextChanged(object sender, EventArgs e)
        {

        }

        protected void ComboCommType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {

        }


    

     
    }
}